//
//  GTStatusCell.swift
//  swiftWEIbo
//
//  Created by mac－gt on 15/11/27.
//  Copyright © 2015年 mac－gt. All rights reserved.
//

import UIKit
// 原始Cell  转发微博和原生微薄的基类
class GTStatusCell: UITableViewCell {
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        setUp()
    }
    var topView: GTCellTopView=GTCellTopView()
    var bottonView: GTBottonView=GTBottonView()
    var   pictureViewWidthCon:NSLayoutConstraint?
    var pictureViewHeightCon:NSLayoutConstraint?
    //
    var status: GTStatus?{
        didSet{
            topView.status=status
            contentLabel.text=status?.text
            pictureView.status=status
            let size=pictureView.calcViewSize()
            pictureViewHeightCon?.constant=size.height
            pictureViewWidthCon?.constant=size.width
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // 计算cell的行高
    func rowHeight(status: GTStatus?)->CGFloat{
        self.status=status
        self.layoutIfNeeded()
        return CGRectGetMaxY(bottonView.frame)
    }
    // 添加子控件和约束
    func setUp(){
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(pictureView)
        contentView.addSubview(bottonView)
        bottonView.translatesAutoresizingMaskIntoConstraints=false
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size:CGSize(width:  UIScreen.mainScreen().bounds.size.width, height: 53))
        contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 8, y: 8))
        contentView.addConstraint(NSLayoutConstraint(item: contentLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width-2*8))
            bottonView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: -8, y: 8))
        
    }
    // 懒加载内容Lable
   lazy var contentLabel:UILabel={
        let lable=UILabel()
        lable.numberOfLines=0
        return lable
    }()
    // 懒加载配图View
     lazy var pictureView:GTStatusCollectionView=GTStatusCollectionView()
}
